<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"
%><%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"
%><%@ taglib prefix="security" uri="http://www.springframework.org/security/tags"
%><%@ taglib prefix="spring" uri="http://www.springframework.org/tags"
%><%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"
%><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
%>
<head>
    <title><fmt:message key="field" /></title>
</head>
<body>
	<script language="JavaScript">
	<!--
		dojo.require("dojo.data.ItemFileReadStore");
		dojo.addOnLoad(function() {
			var currentFieldType = ${currentFieldType};
			console.warn(currentFieldType.show);
			dojo.forEach(currentFieldType.show, function(entry, item){
				var item = dojo.byId(entry);
				if(item){
					dojo.style(item, "display", "");
				}
			});
		});
	//-->
	</script>	
    <h1><fmt:message key="field" /></h1>
    <c:url var="updateUrl" value="/domain/field/update"/>
    <form:form action="${updateUrl}" id="fieldForm" modelAttribute="fieldForm" >
        <form:errors cssClass="error"/>
        <table>
            <form:hidden path="field.inode"/>
            <tbody>
                <tr>
                    <th><fmt:message key="field_structureInode" /></th>
                    <td>
                        <form:hidden path="field.structureInode" />
						<c:out value="${fieldForm.field.structure.name}" />
                    </td>
                </tr>
                <tr>
                    <th><fmt:message key="field_fieldType" /> *</th>
                    <td>
						<form:select path="field.fieldType" disabled="true">
						</form:select>
                        <script type="text/javascript">
                            Spring.addDecoration(new Spring.ElementDecoration({
                                elementId : "field.fieldType",
                                widgetType : "dijit.form.FilteringSelect",
                                widgetAttrs : {
									id: "elementSelectBox",
									value: '${fieldForm.field.fieldType}',
									store: new dojo.data.ItemFileReadStore({data: ${fieldTypeData}}),
									searchAttr: "id",
									labelAttr: "displayName",
									labelType: "html",
                                    required : true
                                }
                            }));
                        </script>
                        <form:errors cssClass="error" path="field.fieldType"/>
                    </td>
                </tr>
                <tr id="labelRow">
                    <th><fmt:message key="field_fieldName" /></th>
                    <td>
                        <form:input path="field.fieldName"/>
                        <script type="text/javascript">
                            Spring.addDecoration(new Spring.ElementDecoration({
                                elementId : "field.fieldName",
                                widgetType : "dijit.form.ValidationTextBox",
                                widgetAttrs : {
                                    required : false
                                }
                            }));
                        </script>
                        <form:errors cssClass="error" path="field.fieldName"/>
                    </td>
                </tr>
                <tr id="velocityVarRow">
                    <th><fmt:message key="field_velocityVarName" /></th>
                    <td>
                        <form:input path="field.velocityVarName"/>
                        <script type="text/javascript">
                            Spring.addDecoration(new Spring.ElementDecoration({
                                elementId : "field.velocityVarName",
                                widgetType : "dijit.form.ValidationTextBox",
                                widgetAttrs : {
                                    required : true
                                }
                            }));
                        </script>
                        <form:errors cssClass="error" path="field.velocityVarName"/>
                    </td>
                </tr>

                <tr id="required">
                    <th><fmt:message key="field_required" /></th>
                    <td>
                        <form:checkbox id="field.required" path="field.required"/>
                        <script type="text/javascript">
                            Spring.addDecoration(new Spring.ElementDecoration({
                                elementId : "field.required",
                                widgetType : "dijit.form.CheckBox",
                                widgetAttrs : {
                                    checked: ${fieldForm.field.required != null ? fieldForm.field.required : false}
                                }
                            }));
                        </script>
                        <form:errors cssClass="error" path="field.required"/>
                    </td>
                </tr>

                <tr id="dataTypeRow" style="display:none" class="candidateRow">
                    <th><fmt:message key="field_dataType" /></th>
                    <td>
						<ul>

						<c:forEach items="${dataTypeList}" var="field" varStatus="status">
						<li id="radio${field.displayName}" style="display:none" class="candidateRow">
							<c:choose>
							<c:when test="${field.displayName == fieldForm.dataType}">
							<input type="radio" name="dataType" id="dataType${field.displayName}" 
								value="${field.displayName}" checked="true" />
							<label for="dataType${field.displayName}">${field.localDisplayName}</label> &nbsp;
									

							</c:when>
							<c:otherwise>
							<input type="radio" name="dataType" id="dataType${field.displayName}" 
								value="${field.displayName}" />
							<label for="dataType${field.displayName}">${field.localDisplayName}</label> &nbsp;
							</c:otherwise>
							</c:choose> 
						</li>
						</c:forEach>
						</ul>
                    </td>
                </tr>

                <tr id="valueRow" style="display:none" class="candidateRow">
                    <th><fmt:message key="field_fieldValues" /></th>
                    <td>
                        <form:textarea path="field.fieldValues"/>
                        <script type="text/javascript">
                            Spring.addDecoration(new Spring.ElementDecoration({
                                elementId : "field.fieldValues",
                                widgetType : "dijit.form.SimpleTextarea",
                                widgetAttrs : {
                                    required : false
                                }
                            }));
                        </script>
                        <form:errors cssClass="error" path="field.fieldValues"/>
                    </td>
                </tr>
				<tr id="categoryRow" style="display:none" class="candidateRow">
					<th><fmt:message key="field_categories" /></th>
					<td>
						<form:select path="categoryId">
							<form:options items="${categoryGroupList}" itemValue="x" itemLabel="displayName" />
						</form:select>

                        <script type="text/javascript">
                            Spring.addDecoration(new Spring.ElementDecoration({
                                elementId : "categoryId",
                                widgetType : "dijit.form.FilteringSelect",
                                widgetAttrs : {
                                    required : false
                                }
                            }));
                        </script>
					</td>
				</tr>
                <tr id="validationRow" style="display:none" class="candidateRow">
                    <th><fmt:message key="field_regexCheck" /></th>
                    <td>
                        <form:input path="field.regexCheck"/>
                        <script type="text/javascript">
                            Spring.addDecoration(new Spring.ElementDecoration({
                                elementId : "field.regexCheck",
                                widgetType : "dijit.form.ValidationTextBox",
                                widgetAttrs : {
                                    required : false
                                }
                            }));
                        </script>
                        <form:errors cssClass="error" path="field.regexCheck"/>
						<form:select path="validation">
							<form:options items="${validationList}" itemValue="value" itemLabel="displayName" />
						</form:select>
                        <script type="text/javascript">
                            Spring.addDecoration(new Spring.ElementDecoration({
                                elementId : "validation",
                                widgetType : "dijit.form.FilteringSelect",
                                widgetAttrs : {
									onChange: function(value) {
										dijit.byId('field.regexCheck').attr('value', value);
									},
                                    required : false
                                }
                            }));
                        </script>
                    </td>
                </tr>
                <tr id="defaultText" style="display:none" class="candidateRow">
                    <th><fmt:message key="field_defaultValue" /></th>
                    <td>
                        <form:input path="field.defaultValue"/>
                        <script type="text/javascript">
                            Spring.addDecoration(new Spring.ElementDecoration({
                                elementId : "field.defaultValue",
                                widgetType : "dijit.form.ValidationTextBox",
                                widgetAttrs : {
                                    required : false
                                }
                            }));
                        </script>
                        <form:errors cssClass="error" path="field.defaultValue"/>
                    </td>
                </tr>

                <tr id="hintText" style="display:none" class="candidateRow">
                    <th><fmt:message key="field_hint" /></th>
                    <td>
                        <form:input path="field.hint"/>
                        <script type="text/javascript">
                            Spring.addDecoration(new Spring.ElementDecoration({
                                elementId : "field.hint",
                                widgetType : "dijit.form.ValidationTextBox",
                                widgetAttrs : {
                                    required : false
                                }
                            }));
                        </script>
                        <form:errors cssClass="error" path="field.hint"/>
                    </td>
                </tr>
                <tr id="userSearchable" style="display:none" class="candidateRow">
                    <th><fmt:message key="field_searchable" /></th>
                    <td>
                        <form:checkbox id="field.searchable" path="field.searchable"/>
                        <script type="text/javascript">
                            Spring.addDecoration(new Spring.ElementDecoration({
                                elementId : "field.searchable",
                                widgetType : "dijit.form.CheckBox",
                                widgetAttrs : {
                                    checked: ${fieldForm.field.searchable != null ? fieldForm.field.searchable : false}
                                }
                            }));
                        </script>
                        <form:errors cssClass="error" path="field.searchable"/>
                    </td>
                </tr>
                <tr id="indexed" style="display:none" class="candidateRow">
                    <th><fmt:message key="field_indexed" /></th>
                    <td>
                        <form:checkbox id="field.indexed" path="field.indexed"/>
                        <script type="text/javascript">
                            Spring.addDecoration(new Spring.ElementDecoration({
                                elementId : "field.indexed",
                                widgetType : "dijit.form.CheckBox",
                                widgetAttrs : {
                                    checked: ${fieldForm.field.indexed != null ? fieldForm.field.indexed : false}
                                }
                            }));
                        </script>
                        <form:errors cssClass="error" path="field.indexed"/>
                    </td>
                </tr>
                <tr id="listed" style="display:none" class="candidateRow">
                    <th><fmt:message key="field_listed" /></th>
                    <td>
                        <form:checkbox id="field.listed" path="field.listed"/>
                        <script type="text/javascript">
                            Spring.addDecoration(new Spring.ElementDecoration({
                                elementId : "field.listed",
                                widgetType : "dijit.form.CheckBox",
                                widgetAttrs : {
                                    checked: ${fieldForm.field.listed != null ? fieldForm.field.listed : false}
                                }
                            }));
                        </script>
                        <form:errors cssClass="error" path="field.listed"/>
                    </td>
                </tr>
                <tr id="unique" style="display:none" class="candidateRow">
                    <th><fmt:message key="field_unique_" /></th>
                    <td>
                        <form:checkbox id="field.unique_" path="field.unique_"/>
                        <script type="text/javascript">
                            Spring.addDecoration(new Spring.ElementDecoration({
                                elementId : "field.unique_",
                                widgetType : "dijit.form.CheckBox",
                                widgetAttrs : {
                                    checked: ${fieldForm.field.unique_ != null ? fieldForm.field.unique_ : false}
                                }
                            }));
                        </script>
                        <form:errors cssClass="error" path="field.unique_"/>
                    </td>
                </tr>

            </tbody>
            <tfoot>
                <tr>
                    <td colspan="2">
                        <div class="buttons">
                            <button id="saveButton" class="ok" type="submit"><fmt:message key="label.form.submit"/></button>
                            <script type="text/javascript">
                                Spring.addDecoration(new Spring.ValidateAllDecoration({
                                    elementId:'saveButton',
                                    event:'onclick'
                                }));
                            </script>
                        </div>
                    </td>
                </tr>
            </tfoot>
        </table>
    </form:form>
</body>
